Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Experts, I am new to linux and need to know the output of this code. I dont have linux system with me right now. Can anyone please help me ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    1

    Please tell the output of this code

    Hi Experts,

    I am new to linux and need to know the output of this code. I dont have linux system with me right now. Can anyone please help me out giving me the out put of these two programs.

    Program1:

    s o c k a d d r i n s e r v e rAd d r ;
    s o c k addr &s e r v e rAd d rCa s t = ( s o c k addr &) s e r v e rAd d r ;
    // ge t a t cp / i p s o c k e t
    i n t l i s t e n F d = s o c k e t (AF INET , SOCK STREAM, 0 ) ;

    bz e r o (&s e r v e rAddr , s i z e o f ( s e r v e rAd d r ) ) ;
    s e r v e rAd d r . s i n f ami l y = AF INET ;
    // any i n t e r n e t i n t e r f a c e on t h i s s e r v e r .
    s e r v e rAd d r . s i n a d d r . s a d d r = h t o n l (INADDR ANY) ;
    s e r v e rAd d r . s i n p o r t = htons ( 1 3 ) ;

    bind ( l i s t e n F d , &s e r v e rAd d rCa s t , s i z e o f ( s e r v e rAd d r ) ) ;

    l i s t e n ( l i s t e n F d , 5 ) ;

    f o r ( ; ; ) { 18 i n t connectFd =
    a c c e pt ( l i s t e n F d , ( s o c k addr ) NULL, NULL ) ;
    // . . r e ad and wr i t e o p e r a t i o n s on connectFd . .
    shutdown ( connectFd , 2 ) ;
    c l o s e ( connectFd ) ;
    }




    Program2:

    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    #define SOCK_PATH "echo_socket"

    int main(void)
    {
    int s, s2, t, len,n;
    struct sockaddr_un local, remote;
    char str[100];
    s = socket(AF_UNIX, SOCK_STREAM, 0);
    local.sun_family = AF_UNIX;
    strcpy(local.sun_path, SOCK_PATH);
    unlink(local.sun_path);
    len = strlen(local.sun_path) + sizeof(local.sun_family);
    bind(s, (struct sockaddr *)&local, len);
    listen(s, 5);
    printf("Waiting for a connection...\n");
    t = sizeof(remote);
    s2 = accept(s, (struct sockaddr *)&remote, &t);
    printf("Connected.\n");
    while (1)
    {
    n = recv(s2, str, 100, 0);
    send(s2, str, n, 0);
    }
    close(s2);
    return 0;
    }

  2. #2
    Linux Newbie danielsmw's Avatar
    Join Date
    Nov 2006
    Location
    Clemson, SC / Charleston, SC
    Posts
    110
    My first suggestion would be to either (a) carry a linux system with you if you're going to need it, or (b) sign up for a shell accounts. There's hundreds of places you can do this online or with educational institutions, and then all you would have to do is ssh to it from any internet-connected computer in the world (if you're on Windows, you could download and use PuTTY, a free ssh client).

    And if you don't mind me asking, why do you need to know the output of this code? It's just a simple networking suite. Unless you have a good reason, not many people are going to feel like downloading that code (and then having to mess with reformatting that first one), compiling (possibly debugging first), and running unless you have a pretty good reason for it. Make sure you've read http://www.linuxforums.org/forum/lin...ums-rules.html and let me know if you need help finding a shell account.
    Registered Linux User: #479567
    Asking a question? Read this page first.
    Now... sudo make me a sandwich.
    ratiocinativeroot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...