I have write some socket program at Unix(sun-solaris).
With the socket-api "getpeername",
I can get the IP of a machine that connect to my machine.
Now,I must write a daemon program at Unix(sun-solaris).
I can get the information that the client send to my machine.
But,how can I get the IP that connect to my machine at my daemon-program???
I provide an sample code,I wish my answer can write some code in my program.
Let me know how can I get the IP of a machine that connect to my machine
and let me see and check the answer is correct.
Thanks......
// daemon sample code
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
int main(void)
{
char ap_command[1024];
memset(ap_command,'\0',1024);
setvbuf(stdout,NULL,_IOLBF,0);
///////////////////////////////////////////
// How can I get the IP-address of a machine
// that connect to my machine.
///////////////////////////////////////////
while(fgets(ap_command,sizeof(ap_command),stdin) != NULL)
{
printf("ECHO:%s\n\r",ap_command);
memset(ap_command,'\0',1024);
}
return(0);
} |