×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

IP to string and break down the string

IP to string and break down the string

IP to string and break down the string

(OP)
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.

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);
 

RE: IP to string and break down the string

(OP)
thank you

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close