simple socket problem.

This is a discussion on simple socket problem. within the C Programming forums, part of the General Programming Boards category; i am getting a curios error from my socket() call. socket: Socket operation on non-socket. whats that supposed to mean? ...

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214

    simple socket problem.

    i am getting a curios error from my socket() call.
    socket: Socket operation on non-socket.

    whats that supposed to mean?
    Code:
    #include <stdio.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <netdb.h>
    
    #define DEST_PORT 139
    
    int main (int argc, char *argv[])
    {
    	if (argc < 2)
    		printf("usage: %s <destination_ip>", argv[0]);
    
    	int sockfd;
    
    	struct sockaddr_in dest;
    
    	if((sockfd = socket(AF_INET, SOCK_STREAM, 0) == - 1))
    		perror("socket");
    
    	dest.sin_family = AF_INET;
    	dest.sin_port = htons(DEST_PORT);
    	dest.sin_addr.s_addr = inet_addr(argv[1]);
    	memset(&(dest.sin_zero), '\0', 8);
    
    	if ((connect(sockfd, (struct sockaddr *)&dest, sizeof(struct sockaddr))) == - 1)
    		perror("connect");
    	
    	return 0;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    A simple mistake

    Change this:
    >>if((sockfd = socket(AF_INET, SOCK_STREAM, 0) == - 1))

    To this:
    >>if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == - 1)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    really simple.
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Listening socket and thread problem
    By esaptonor in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2010, 04:04 AM
  2. simple JPEG problem
    By the bassinvader in forum C Programming
    Replies: 6
    Last Post: 10-05-2006, 06:45 PM
  3. Datagram Unix socket problem
    By karas in forum C Programming
    Replies: 9
    Last Post: 07-27-2006, 11:08 AM
  4. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  5. problem closing a socket
    By Wisefool in forum C Programming
    Replies: 1
    Last Post: 10-28-2003, 01:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21