Coder's Guild Mailing List

Re: Linux C Struct Problem

Posted by evilhackr on 2001-02-06

Heres some code from it.....
-==================================================-
struct recv {
 int flag;
 int b[4];
 char nextpass[10];
};

typedef struct recv t_recv;

struct send {
 int answer;
 char prevpass[10];
};

typedef struct send t_send;

int main(int argc, char *argv[])
{
 int sockfd, numbytes;
 struct hostent *he;
 struct sockaddr_in their_addr;

 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  perror("socket");
  exit(1);
 }

 their_addr.sin_family = AF_INET;
 their_addr.sin_port = htons(PORT);
 their_addr.sin_addr = *((struct in_addr *)he->h_addr);
 bzero(&(their_addr.sin_zero), 8);

 if (connect(sockfd, (struct sockaddr *)&their_addr, \
     sizeof(struct sockaddr)) == -1)
 {
  perror("connect");
  exit(1);
 }

 if ((numbytes=recv(sockfd, b, MAXDATASIZE, 0)) == -1)
 {
  perror("recv");
  exit(1);
 }

 b[numbytes] = '\0';
 printf("Values: %s\n", b);
 close(sockfd);
 return 0;
}

-==================================================-
I removed some of the host resolve stuff so when you see some extra uneeded
code
it's prolly cause I got rid of that area. What this script is supposed to do
when I'm completly
done with it is connect to port 2345 of whatever host I specify and take the
four ints (numbers) and
multiply them by each other and then send the value back. This is for help
with socket programming.
I'm determined to find the answers to my problems. Thanks to anyone for
responding.

    Paul/nonex/evilhackr [evilhackr@xxxxxxxxx.xxx]