Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. incloming socket address

incloming socket address

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmintutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kristian33
    wrote on last edited by
    #1

    I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

    R M N O K 5 Replies Last reply
    0
    • K Kristian33

      I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

      R Offline
      R Offline
      Rickard Andersson20
      wrote on last edited by
      #2

      getpeername(...) Rickard Andersson@Suza Computing ICQ#: 50302279 (Add me!) E-mail: nikado@pc.nu I'm from the winter country SWEDEN!

      1 Reply Last reply
      0
      • K Kristian33

        I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

        M Offline
        M Offline
        markkuk
        wrote on last edited by
        #3

        inet_ntoa() will convert a struct in_addr into dotted number string format.

        1 Reply Last reply
        0
        • K Kristian33

          I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          inet_ntoa(from.sin_addr) Nish p.s. from is a sockaddr_in


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          1 Reply Last reply
          0
          • K Kristian33

            I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

            O Offline
            O Offline
            Orbital
            wrote on last edited by
            #5

            It goes like this : if((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) { perror("accept"); } printf("server: got connection from %s\n", inet_ntoa(their_addr.sin_addr)); The remote adrese is returned by the secondn parameter of 'accept' function Bye, Orbital^ ...the night is long ... but not long enought to do some real coding ...

            1 Reply Last reply
            0
            • K Kristian33

              I have socket server and i would want to know, how to print client sockets address to screen. Is there so function, that makes it to normal ip address form (e.x 120.1.1.2)

              K Offline
              K Offline
              Kristian33
              wrote on last edited by
              #6

              Thanks to you all

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups