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.
精彩评论