Read the Port Number from sd card Ethernet shield w5100

Hi ,I am having sd card in ethernet shield of text file containing:

DE:AD:BE:EF:FE:ED
192.168.10.11
255.255.255.0
192.168.10.3
59.144.127.16
192.168.10.105
6666

MAC,IP,SM,GW,DNS,SERVER IP,PORT NUMBER
I can read till server ip …but having problem in reading port number because it is long in data type …how to write function read that port number?

this is my code:

#include "SdFat.h"
SdFat SD;
#include<SPI.h>
#include<Ethernet.h>
byte mymac[6];
byte myip[4];
byte mynm[4];
byte mygw[4];
byte mydns[4];
byte server[4];
EthernetClient client;
void setup() {
  Serial.begin(115200);
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  delay(2000);
  if (!SD.begin(4)) {
    Serial.println( F("SD fail") );
    delay(1000);
  }
  else Serial.println( F("SD ok") );
  File fh = SD.open("nw_set2.txt", FILE_READ);
  char netbuffer[32];
  if (!fh)
  { Serial.println( F("SD open fail") );
    return;
    delay(1000);
  }
  int chpos = 0;
  int lineno = 0;
  while (fh.available())
  {
    char ch = fh.read();
    if (ch == '\n') {
      chpos = 0;
      switch (lineno) {
        case 0:
          if (getmac(netbuffer, mymac)); //Serial.println(F("mac ok"));
          break;
        case 1:
          if (getip(netbuffer, myip)); //Serial.println(F("ip ok"));
          break;
        case 2:
          if (getip(netbuffer, mynm)); //Serial.println(F("sm ok"));
          break;
        case 3:
          if (getip(netbuffer, mygw)); //Serial.println(F("gw ok"));
          break;
        case 4:
          if (getip(netbuffer, mydns)); //Serial.println(F("dns ok"));
          break;
        case 5:
          if (getip(netbuffer, server)); //Serial.println(F("server is ok"));
          break;
      }
      lineno++;

    }
    else if (ch == '\r') {
      //do nothing
    }
    else if (chpos < 31) {
      netbuffer[chpos] = ch;
      chpos++;
      netbuffer[chpos] = 0;
    }
  }
  fh.close();



  Serial.print( F("\r\nmac") );
  printArrayTo( Serial, mymac, sizeof(mymac), ':' );

  Serial.print( F("\r\nip") );
  printArrayTo( Serial, myip, sizeof(myip), '.' );

  Serial.print( F("\r\nNM") );
  printArrayTo( Serial, mynm, sizeof(mynm), '.' );

  Serial.print( F("\r\ngw") );
  printArrayTo( Serial, mygw, sizeof(mygw), '.' );

  Serial.print( F("\r\ndns") );
  printArrayTo( Serial, mydns, sizeof(mydns), '.' );

  Serial.print( F("\r\nserver") );
  printArrayTo( Serial, server, sizeof(server), '.' );

  //Serial.println( F("\r\nStrating ethernet") );
  Ethernet.begin(mymac, myip, mydns, mygw, mynm);
  //Serial.println(Ethernet.localIP());


  Serial.println( F("connecting...") );
  delay(5000);
  if (client.connect(server, 6666)) {
    Serial.println( F("connected") );
  } else {
    Serial.println( F("connection failed") );
    delay(1000);

  }

}

void loop() {



}


void printArrayTo( Stream & out, byte *array, size_t size, char delim )
{
  for (size_t i = 0; i < size; i++) {
    // print one number
    out.print( *array++ );

    // print the delimiter, but not after the last byte
    if (i < size - 1)
      out.print( delim );
  }
}

byte getmac(char* macbuf, byte* thismac) {
  byte thislen = strlen(macbuf);
  byte thisoctet = 1;
  thismac[0] = strtol(&macbuf[0], NULL, 16);
  for (int x = 0; x < thislen; x++) {
    if (macbuf[x] == ':') {
      thismac[thisoctet] = strtol(&macbuf[x + 1], NULL, 16);
      thisoctet++;
    }
  }
  if (thisoctet == 6)return (1);
  else return (0);
}


byte getip(char* ipbuf, byte* thisip) {
  byte thislen = strlen(ipbuf);
  byte thisoctet = 1;
  thisip[0] = atoi(&ipbuf[0]);
  for (int x = 0; x < thislen; x++) {
    if (ipbuf[x] == '.') {
      thisip[thisoctet] = atoi(&ipbuf[x + 1]);
      thisoctet++;
    }
  }
  if (thisoctet == 4)return (1);
  else return (0);
}

You shouldn't need a separate function to read the port number from the last line. Just Declare a variable for the port number like..

unsigned short portNo;

Then before you zero out the current character position with chpos=0, you would need to terminate the netbuffer with a null in the last position to make it a valid string containing the port number in ASCII characters...

netbuffer[chpos] = 0;

and then for "case 6" in the switch statement you could just use something like

portNo = atoi(netbuffer);

Hope this helps...