Issue in building lsock in Sierra OSX10.12

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Issue in building lsock in Sierra OSX10.12

Postby abhirs » Thu Apr 06, 2017 1:09 am

Hi Friends,
I am trying to implement a network collector by using apple's private Network. Thanks to Jonathan Levin.
I got a the sample code from https://github.com/sotrosh/lsock, which I am trying to build and work in Mac OSX 10.12 machine using xCode 8.3. So that I can able to view and understand how each functions in lsock.c is working.
Also there is a function called getOsVer(), But for testing in 10.12, I have added.

Code: Select all
void getOsVer()
{

   struct utsname name;

   uname (&name);
       // ugly hack, for now.. This works with iOS as well, since the structs are common

  if (strstr(name.version, "xnu-24"))
        {
        g_OsVer = 9;
        }
  else if (strstr(name.version, "xnu-20"))
   {
        g_OsVer = 8;
        }
  else if (strstr(name.version, "xnu-27"))
        {
        g_OsVer = 10;
        }
  else if (strstr(name.version, "xnu-37")) {
        g_OsVer = 12;
       }
}


Now the problem is when I add these files in Xcode I am getting lot of compilation errors. Have anybody faced similar problem? Kindly suggest.

Compilation errors:

Undefined symbols for architecture x86_64:
"_cbreak", referenced from:
_main in lsock.o
"_endwin", referenced from:
_main in lsock.o
"_init_pair", referenced from:
_print_descriptors in lsock.o
"_initscr", referenced from:
_main in lsock.o
"_nodelay", referenced from:
_main in lsock.o
"_noecho", referenced from:
_main in lsock.o
"_start_color", referenced from:
_main in lsock.o
..........

"_wmove", referenced from:
_print_header in lsock.o
_print_descriptors in lsock.o
"_wrefresh", referenced from:
_print_descriptors in lsock.o
ld: symbol(s) not found for architecture x86_64
abhirs
 
Posts: 10
Joined: Thu Apr 06, 2017 12:50 am

Re: Issue in building lsock in Sierra OSX10.12

Postby abhirs » Thu Apr 06, 2017 5:37 am

After several attempt,
I am able to solve the issue by doing the following:

choose project details
choose build phases tab
open link binary with libraries part
click the plus symbol
add libncurses.dylib to your project.
But if you are running or compiling the application on 10.12 machine with Xcode 8.3 then you would be adding libncurses.tbd to the project. And it will appear under Frameworks in project navigator.
abhirs
 
Posts: 10
Joined: Thu Apr 06, 2017 12:50 am

Re: Issue in building lsock in Sierra OSX10.12

Postby Siguza » Thu Apr 06, 2017 7:09 pm

Are you condemned to use Xcode? Because if not, the terminal has a so much simpler solution:

Code: Select all
gcc -o lsock lsock.c -lncurses
User avatar
Siguza
Unicorn
 
Posts: 159
Joined: Thu Jan 28, 2016 10:38 am

Re: Issue in building lsock in Sierra OSX10.12

Postby abhirs » Fri Apr 07, 2017 1:47 am

Thank you Siguza for the reply and great suggestion.
Since I am more comfortable to debug using Xcode than the terminal. Thats why I ported to xcode8. After adding the library libncurses.tbd to Xcode it compiled successfully. Then another problem popped up as the source code says we need to integrate to Terminal. I found some solution from google to launch and attach the terminal to my Xcode application. I am able to debug the lsock now. Now I am stuck in the following place
Code: Select all
  // check rc. Meh.

  if (rc > 0)
   {
     nstat_msg_hdr *ns = (nstat_msg_hdr *) c;

  switch (ns->type)
   {
   
   case 10001: case 10002: case 10003: case 10004:
        rc = process_nstat_msg(c,rc);
      break;

   case 0:
      // Got all sources, or all counts
      // if we were getting sources, ask now for all descriptions

ns->type always return 1 and I am not able to get any network data. I don't know the answer yet. Please suggest me. Thanks again for your addressing my issue.
/Ab
abhirs
 
Posts: 10
Joined: Thu Apr 06, 2017 12:50 am

Re: Issue in building lsock in Sierra OSX10.12

Postby morpheus » Fri Apr 07, 2017 2:06 am

People,

please don't use GitHub mirrors. I don't post my code to GitHub. Get the official updated code from this site, and if something doesn't work or you want to contribute - that's what the forum is for. Mirrors will either branch unnecessarily or introduce bugs and quirks I can't be responsible for.

Updated version of lsock updated *on this site* will post later tonight.

J
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: Issue in building lsock in Sierra OSX10.12

Postby abhirs » Fri Apr 07, 2017 2:26 am

Wow Thats super cool morpheus. Thank you so much and it will be of great help
I am looking forward to get the updated version lsock for osX10.12.
Thank you
Ab
abhirs
 
Posts: 10
Joined: Thu Apr 06, 2017 12:50 am

Re: Issue in building lsock in Sierra OSX10.12

Postby backendbilly » Fri Apr 07, 2017 2:53 am

Also there is a function called getOsVer(), But for testing in 10.12, I have added.


Many structures/enums have changed in the XNU 3789. You will need to implement more than just getOSVer(). Take a look at lsock.h. You need to add/modify various structs and enums in there including "nstat_tcp_descriptor_10_12" which should include the new additions/modifications in XNU 3789. More specically, take a look under XNU -> /bsd/net/ntstat.h and grap the nstat_tcp_descriptor from there and add it to lsock.h. Name it nstat_tcp_descriptor_10_12 for example. Also note that the first enum in lsock.h does not include the new addtions including NSTAT_PROVIDER_TCP_KERNEL and NSTAT_PROVIDER_UDP_KERNEL. Once those are added, you will need to update lsock.c with these new additions.
backendbilly
Site Admin
 
Posts: 132
Joined: Fri May 29, 2015 5:58 pm

Re: Issue in building lsock in Sierra OSX10.12

Postby abhirs » Fri Apr 07, 2017 2:59 am

backendbilly wrote:
Also there is a function called getOsVer(), But for testing in 10.12, I have added.


Many structures/enums have changed in the XNU 3789. You will need to implement more than just getOSVer(). Take a look at lsock.h. You need to add/modify various structs and enums in there including "nstat_tcp_descriptor_10_12" which should include the new additions/modifications in XNU 3789. More specically, take a look under XNU -> /bsd/net/ntstat.h and grap the nstat_tcp_descriptor from there and add it to lsock.h. Name it nstat_tcp_descriptor_10_12 for example. Also note that the first enum in lsock.h does not include the new addtions including NSTAT_PROVIDER_TCP_KERNEL and NSTAT_PROVIDER_UDP_KERNEL. Once those are added, you will need to update lsock.c with these new additions.

Thank you for the reply. Yes I saw that /xnu-10.12/bsd/net/ntstat.h file. Need to implement that. Also I heard from "morpheus" that he have an updated version of lsock for OSX10.12 and will be uploading here. Hope that will be of great help. reference [http://newosxbook.com/forum/viewtopic.php?f=7&t=16616]
abhirs
 
Posts: 10
Joined: Thu Apr 06, 2017 12:50 am


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 1 guest

cron