Search Results

Search found 1 results on 1 pages for 'curlystraw'.

Page 1/1 | 1 

  • sockaddr_in causing segfault?

    - by Curlystraw
    Working on creating a server/client system in C right now, and I'm having a little trouble with the client part. From what I've seen, I need to use sockaddr_in so I can connect to the server. However, I've been getting a segfault every time. I believe that sockaddr_in has something to do with it, as comment it and it's references later in the program fixes the segfault. code: #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> int main(int argc, char** argv) { int Csock; int con; char *data = 0; char buf[101] = ""; struct sockaddr_in addr; Csock = socket(AF_INET, SOCK_STREAM, 0); addr.sin_family = AF_INET; addr.sin_port = htons(3435); con = connect(Csock, (struct sockaddr*) &addr, sizeof(&addr)); write(con, "Text", sizeof("Text")); *data = read(con, buf, 100); puts(data); return 0; } sadly, I am rather new to C, so that's as much as I can figure... can anyone tell me a way to go about eliminating the segfault? Thanks!

    Read the article

1