about connect - TCP-IP

This is a discussion on about connect - TCP-IP ; Hello, I'm a newbie programming in assembler, and I'm trying to implement a tiny-wget function in a program I'm doing. I'm also new to network programming, my target os is linux. One of the problems I'm facing is `connect'. it ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: about connect

  1. about connect

    Hello,

    I'm a newbie programming in assembler, and I'm trying to implement a
    tiny-wget function in a program I'm doing.

    I'm also new to network programming, my target os is linux. One of the
    problems I'm facing is `connect'. it doesn't exist as such in assembler
    as it does in c. Though I've had hard times with google lookin for some
    sort of explanation to this regard, I haven't found anything that makes
    me understand.

    Currently all that I'm able to do is this:

    http://es.geocities.com/ucho_trabajo/asm/tcp.s.txt

    Which is nothing but a call to `socket', aquiring a socket descriptor.
    For ease I'm curently trying to connect to my sendmail daemon, since
    being able to retrieve something from it, might mean that I would as
    well with a ftp or http addres.

    Althought I've got nice examples like this:

    http://asm.sourceforge.net/articles/...rc.html#socket

    I just cannot figure out how a call that tries to connect to a website
    or ftp, trying to retrieve data could be done.

    I know I can link to libc and use `connect' but it's not what I'm
    trying to. So I'm wondering if any expert could roughly describe the
    process at such level for me, so I can implement it.

    Kind Regards,


  2. Re: about connect

    In article <1150289464.309495.102720@f6g2000cwb.googlegroups.c om>,
    "Chinlu" wrote:

    > Hello,
    >
    > I'm a newbie programming in assembler, and I'm trying to implement a
    > tiny-wget function in a program I'm doing.
    >
    > I'm also new to network programming, my target os is linux. One of the
    > problems I'm facing is `connect'. it doesn't exist as such in assembler
    > as it does in c. Though I've had hard times with google lookin for some
    > sort of explanation to this regard, I haven't found anything that makes
    > me understand.


    How do you invoke other system calls that take structures as parameters,
    like stat()? There's nothing different about connect() in this regard.
    You need to determine the mapping from C structures to raw memory
    layout, and then fill in a block of memory appropriately in your
    program. You can do this by writing a C program that calls connect()
    and then looking at the generated assembler from your compiler.

    >
    > Currently all that I'm able to do is this:
    >
    > http://es.geocities.com/ucho_trabajo/asm/tcp.s.txt
    >
    > Which is nothing but a call to `socket', aquiring a socket descriptor.
    > For ease I'm curently trying to connect to my sendmail daemon, since
    > being able to retrieve something from it, might mean that I would as
    > well with a ftp or http addres.


    Huh? You don't retrieve things from sendmail, it's used to send mail
    out.

    >
    > Althought I've got nice examples like this:
    >
    > http://asm.sourceforge.net/articles/...rc.html#socket
    >
    > I just cannot figure out how a call that tries to connect to a website
    > or ftp, trying to retrieve data could be done.
    >
    > I know I can link to libc and use `connect' but it's not what I'm
    > trying to. So I'm wondering if any expert could roughly describe the
    > process at such level for me, so I can implement it.


    I'm not sure what else you expect to do. Connect() is the only
    documented API for this. Internally it may perform other operations,
    but that's system-dependent.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  3. Re: about connect

    Hello,

    > How do you invoke other system calls that take structures as parameters,
    > like stat()? There's nothing different about connect() in this regard.
    > You need to determine the mapping from C structures to raw memory
    > layout, and then fill in a block of memory appropriately in your
    > program. You can do this by writing a C program that calls connect()
    > and then looking at the generated assembler from your compiler.


    I use to, but either, the output it's so verbose that I get lost in it,
    or I'm not able to understand it. Too less experienced I'd say.

    My confusion was more due to the overall structure and workflow, as I
    was missing linux/net.h, where sys_connect is defined. I started
    understanding when I saw it that there's an atomic system call which is
    `socketcall', that gets driven by this definitions.

    > Huh? You don't retrieve things from sendmail, it's used to send mail
    > out.


    I was refering to the greeting message or however it is called, as you
    can see if you telnet almost any server. I achieved this yesterday, you
    can see the first results in here:

    http://es.geocities.com/ucho_trabajo/asm/connect2.s.txt
    http://es.geocities.com/ucho_trabajo...ct2.strace.txt
    http://es.geocities.com/ucho_trabajo...nnect2.out.txt

    > I'm not sure what else you expect to do. Connect() is the only
    > documented API for this. Internally it may perform other operations,
    > but that's system-dependent.


    Yes, and that leads me to another question. Yesterday, someone was kind
    enough to post a daytime client program written in assembler, for
    `gas'. And I could see how endianness was more or less handled.

    Trying to get the best out of my flu, I started porting my app. to a
    `.S' extension and compiling it through `gcc' instead of `as', so I can
    get advantage on `gcc' and cpp's macro-proccesing capabilities, which
    makes `gas' more flexible and powerfull, I might add.

    I was also reading the autobook and autoconf/automake info pages, so I
    could start looking at portability issues from other perspective, and
    making this code more or less shareable from the begining. I'm using a
    config header and included:

    #if HAVE_CONFIG_H
    # include
    #endif

    At the top of my assembler file. My question is, I guess I should get
    to know target host's endiannes via some sort of m4 or autoconf macro,
    and then write a:

    #def big_endian
    or
    #def little_endian

    in my `config.h'. Then, throughout all of my program I should split
    code depending on endiannes, like this:

    #ifdef big_endian
    ... big endian code ...
    #else
    ... litle endian code ....
    #endif

    Shouldn't I? Also, could you please tell me other things I might be
    aware of if trying to make this code shareable?

    I haven't got a clue on how other systems handle tcp/ip, so by now it's
    only for linuxes, but are there other potential portability issues that
    would stop me from sharing this code with other linuxes?

    Kind Regards,


  4. Re: about connect

    In article <1150374780.733101.202510@y41g2000cwy.googlegroups. com>,
    "Chinlu" wrote:

    > I haven't got a clue on how other systems handle tcp/ip, so by now it's
    > only for linuxes, but are there other potential portability issues that
    > would stop me from sharing this code with other linuxes?


    99.9% of programmers these days use a high-level language like C, not
    assembler. In C the common way to handle endianness is with macros like
    htons() and presentation libraries like XDR. I don't know if there's a
    repository of similar techniques for assembly programming -- if there's
    an assembly newsgroup, that would probably be the best place to start.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread