Announcement

Collapse
No announcement yet.

inet_addr: Variable expected

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • inet_addr: Variable expected

    DIM service AS SOCKADDR_IN
    service.sin_family = %AF_INET
    service.sin_addr = inet_addr("127.0.0.1")
    service.sin_port = htons(9876)

    It errors "Variable expected" on inet_addr.

    Am I doing something wrong here?

    Thanks.

  • #2
    As written 'inet_addr' must be either a FUNCTION or a MACRO....does it have more than one param?

    Well, I suppose it could be an array, where string literal subscripts are not allowed.

    Bascally it looks like the symbol 'inet_addr' is defined inconsistent with the usage shown.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Jay,

      You probably need something like this:

      DIM service AS SOCKADDR_IN
      DIM inetAddr AS In_Addr

      inetAddr.s_Addr = inet_addr("127.0.0.1")
      service.sin_family = %AF_INET
      service.sin_addr = inetAddr
      service.sin_port = htons(9876)

      Or possibly: service.sin_addr.s_addr = inet_addr("127.0.0.1")
      Last edited by Dave Biggs; 27 Jan 2009, 11:22 AM. Reason: Other options
      Rgds, Dave

      Comment


      • #4
        You're missing a union membership
        Code:
        'From WSock32.inc:
        union in_addr
            S_un_b as S_un_b_type
            S_un_w as S_un_w_type
            s_addr as dword
            s as string * 4
        end union
        type sockaddr_in
            sin_family as integer
            sin_port as word
            sin_addr as in_addr '<---is a union inside a type
            sin_zero as string * 8
        end type
        declare function inet_addr lib "wsock32.dll" alias "inet_addr" (cp as asciiz) as dword
        '- - - - - - - - - - - - - - - - - - - - - -
        'Your code with union member in bold
        DIM service AS SOCKADDR_IN
        service.sin_family = %AF_INET
        service.sin_addr[b].s_addr[/b] = inet_addr("127.0.0.1")
        service.sin_port = htons(9876)
        I did not lookup .sin_port or htons() to see if that is done correctly, figured you could do that yourself after seeing the change I made to .sin_addr line.

        Cheers,
        Dale

        Comment

        Working...
        X