开发者

enter data from key board

开发者 https://www.devze.com 2023-02-19 15:57 出处:网络
in my program i have done like this, have hard coded the values 172.28.6.87 and stored in keys.pktfltr.ip.ip_src i.ewrote the function like this and executed and it worked also

in my program i have done like this, have hard coded the values 172.28.6.87 and stored in keys.pktfltr.ip.ip_src i.e wrote the function like this and executed and it worked also

inet_aton ("172.28.6.87", &(keys.pktfltr.ip.ip_src));

inet_aton function is

 int inet_aton(const char *cp, struct i开发者_开发百科n_addr *inp);

but now the user will decide which ip address he wants and enters it but the entered ip address should be stored in keys.pktfltr.ip.ip_src. How to do this? i am stuck up on this part


This should do it:

#include <stdio.h>

char buf[32];

if (fgets(buf, sizeof buf, stdin) == buf)
    inet_aton(buf, &(keys.pktfltr.ip.ip_src);

More error-checking (of the conversion call) should of course be added.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号