FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Basic Socket Programming Error in Linux.. Pls help





umeshtangnu
Hi! I don't have experiance in linux C programming. I took a linux socket programming book and tried the first example code but It didn't work. I use these codes.. please help me!
Thanks for your replies

Code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
    int z;                   /* Status return code */
    int s[2];                /* Pair of sockets */
    /*
      * Create a pair of local sockets:
      */
    z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);
    if ( z == -1 ) {
         fprintf(stderr,
             “%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n”,
             strerror(errno));
         return 1;           /* Failed */
    }
    /*
      * Report the socket file descriptors returned:
      */
    printf(“s[0] = %d;\n”,s[0]);
    printf(“s[1] = %d;\n”,s[1]);
    system(“netstat --unix -p”);
    return 0;
}


Error Message:
bora.c: In function ‘main’:
bora.c:18: error: stray ‘\342’ in program
bora.c:18: error: stray ‘\200’ in program
bora.c:18: error: stray ‘\234’ in program
bora.c:18: error: expected expression before ‘%’ token
bora.c:18: error: stray ‘\’ in program
bora.c:18: error: stray ‘\342’ in program
bora.c:18: error: stray ‘\200’ in program
bora.c:18: error: stray ‘\235’ in program
bora.c:25: error: stray ‘\342’ in program
bora.c:25: error: stray ‘\200’ in program
bora.c:25: error: stray ‘\234’ in program
bora.c:25: error: expected expression before ‘%’ token
bora.c:25: error: stray ‘\’ in program
bora.c:25: error: stray ‘\342’ in program
bora.c:25: error: stray ‘\200’ in program
bora.c:25: error: stray ‘\235’ in program
bora.c:26: error: stray ‘\342’ in program
bora.c:26: error: stray ‘\200’ in program
bora.c:26: error: stray ‘\234’ in program
bora.c:26: error: expected expression before ‘%’ token
bora.c:26: error: stray ‘\’ in program
bora.c:26: error: stray ‘\342’ in program
bora.c:26: error: stray ‘\200’ in program
bora.c:26: error: stray ‘\235’ in program
bora.c:27: error: stray ‘\342’ in program
bora.c:27: error: stray ‘\200’ in program
bora.c:27: error: stray ‘\234’ in program
bora.c:27: error: ‘netstat’ undeclared (first use in this function)
bora.c:27: error: (Each undeclared identifier is reported only once
bora.c:27: error: for each function it appears in.)
bora.c:27: error: expected ‘)’ before numeric constant
bora.c:27: error: stray ‘\342’ in program
bora.c:27: error: stray ‘\200’ in program
bora.c:27: error: stray ‘\235’ in program

I used this command to compile

gcc bora.c -o bora `pkg-config --cflags --libs gtk+-2.0`
ashis_csedu
Hello umesh
It seems to me that the code you collected from a tutorial website, where each double quote is converted to back quotes. And you may know that Linux C/C++ compilers like (gcc/g++) does not support back quotes.

Sample erroneous lines from you code -

Code:

 fprintf(stderr,
             “%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n”,
             strerror(errno));


You can easily notice the illegal back quotes before %s and after \n.....
Some other erroneous lines from your code are -
Code:

printf(“s[0] = %d;\n”,s[0]);
    printf(“s[1] = %d;\n”,s[1]);
    system(“netstat --unix -p”);


So, remove the back quotes and place double quotes instead (you can find the double quotes beside your ENTER key on your keyboard.

Study linux socket programming, gather knowledge and then code yourself.

Happy programming,
Ashis
ashis_csedu
Some helpful books include -
"Beginning Linux Programming
--Wrox publication
--writers: Neil Mathew & Richard Stones"


"Professional Linux Programming"
--Wrox publication
--writers: Neil Mathew & Richard stones"


Wishes,
Ashis
ashis_csedu
If you want to grasp Linux networking (not programming the network environment), you can get a certification course like - RHCE (Red Hat Certified Engineer) or CCNA (Cisco Certified Network Associates).

After completion of these courses, you will really enjoy (I bet) programming the network environment especially linux sockets.


Wishes,
Ashis
jabapyth
These errors all arise from back-quotes and foreward-quotes. Replace those and it should compile fine.
Fire Boar
And a quick note: if you're living in Europe, the double quote key is not next to enter - instead, it's probably shift-2.
Related topics
FTP problems --> Use Filezilla and/or active mode
Linux - Need Help
Error in phpBB table>>phpbb_sessions(pls help)
PHPMYADMIN - HELP!!!
Office 2007
socket programming in unix
Pls help, onmouseover popup image frm database
Visual programming under Linux
Stop copy threads from other forums!
Error while creating the SQL table pls help
HTTP 500 - Internal server error in my frihost forum
Basic C Programming Help?
CD copy error... pls help
pls help me while transfer a wp blog
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.