且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除提示问题

更新时间:2023-12-04 09:43:28

如果您想对其进行硬编码,则可以在中间注释掉printf和scanf并添加in = 0;行,或更明智的做法是将它们包装在if块中,并在for循环之后检查i的值.

If you want to hardcode it, you can comment out the printf and scanf in the middle and add a in = 0; line, or more sensibly wrap them in an if block and check the value of i after the for loop.

Could you really not figure this out for yourself?


只计算一下您有多少个接口,如果只有一个,那么就使用它而不是提示它:

Just count how many interfaces you have, and if you only have one, then use it rather than prompting for it:

int count = 0;
while (local->h_addr_list[count] != 0)
    count++

if (count == 1) 
{
    in = 0;
} 
else 
}
    for (i = 0; local->h_addr_list[i] != 0; ++i) 
    {
        memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));
        printf("Interface Number : %d Address : %s\n",i,inet_ntoa(addr));
    }
  
    printf("Enter the interface number you would like to sniff : ");
    scanf("%d",&in);
}