tomchesley
Technical User
I want to take the ip i obtained and put it into a string that i can manipulate but i always get passing argument makes pointer from integer without a cast. I am currently using lynix with gcc as my compiler here is the current code
the strcpy and sscanf lines is where it errors, it seems to work but would like to rid the errors.
the strcpy and sscanf lines is where it errors, it seems to work but would like to rid the errors.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <string.h>
#define DEFAULT_UDP_PORT 1234
int main(int count, char *strings[])
{ int sd;
// int i; //use for counter
int fport; //from port
int lastport = 0; //set last port for compare to from port
int uport; //upper byte of from port
int lport; //lower byte of from port
int sbytes = 20; //# of bytes to send back
int users; //number of users on irc server
int port=DEFAULT_UDP_PORT;
struct sockaddr_in addr;
char buffer[32]; //receive buffer
char sbuffer[32]; //send buffer
char temp[32]={0x0}; //results of netstat
char o1[5], o2[5], o3[5], o4[5]; //set string rep of each octet
int io1, io2, io3, io4; //set int value for each octet
char uip[20]; //user ip
if ( count != 2 )
printf("usage: %s <port>\n...Using UDP default port (%d).\n", strings[0], port);
else
port = atoi(strings[1]);
sd = socket(PF_INET, SOCK_DGRAM, 0);
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;
if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
perror("bind");
while (1)
{ int bytes, addr_len=sizeof(addr);
bytes = recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr*)&addr, &addr_len);
//sscanf(inet_ntoa(addr.sin_addr), "%hu.%hu.%hu.%hu", &ip[0],&ip[1],&ip[2],&ip[3]);
//this is where it errors
strcpy(uip,inet_ntoa(addr.sin_addr));
//store each octet to individual strings?
sscanf(inet_ntoa(addr.sin_addr), "%4[^.].%4[^.].%4[^.].%4[^.]", o1, o2, o3, o4);
//set from port to port received from
}
} fport = ntohs(addr.sin_port);