router: port forwarding on CenturyLink C3000z does not work and I am 99% sure it is hardware related

I have a Zyxtel C3000Z modem / router from CenturyLink. It seems that I don't get port forwarding to work and I think it's a hardware problem. I have the latest firmware version. I am trying to forward port 443 to my web server. I used its application forwarding menu preset for a web server. The connection has just expired. I also tried to manually specify the port with the same results. When I go to canyouseeme.org to verify if the port is open, it is open when port forwarding is active and closed when it is disabled.

As an additional test, I removed all port forwarding rules and temporarily enabled the remote GUI at 443. I get the same result. I made sure I was using https and not http, I copied my external IP to avoid typographical errors, I can access it internally and canyouseeme shows the port open when the remote GUI is enabled and closed when it is disabled. I tried to enable the remote command line for SSH and got the same results. The connection has just expired.

I'm missing something? CenturyLink was no help. Not sure if the manufacturer will help. It seems to be opening the ports but simply not forwarding or something. Maybe you should try to restore the default values ​​or update the firmware again. It is a new modem like the one that had stopped working after a blackout. Does anyone have any other suggestions? Surely it seems like a hardware problem. The interface is horrible, but even if I screwed it up or if there were any other problems between the web server and the router, the remote GUI should work. In general, I do not stick to the routers provided by the ISP because I have had problems with advanced features that are poorly implemented …

What rule (s) says that the holder of a tourist visa that enters through the land border and stays near the port of entry does not need an I-94?

My "friend" (holder of the B2 multiple entry tourist visa) recently entered from Mexico to the US. UU Twice, approximately 10 days apart.

The first entry was through CrossBorder Express (CBX), on a one-way flight into TIJ.

The second entrance was through the entrance port of Otay Mesa, personal lanes for vehicles.

I was with my friend during the second entry. My friend was asked "Where are you staying?"and answered"San Diego"Then the officer asked,"Are you staying in San Diego for the entire duration of your trip?"to which my friend replied"No, I also want to visit Los Angeles."

Then, the officer recommended that my friend go to the building next to the vehicle lanes and pay $ 6 to obtain a "Permit" I-94 and obtain an entry stamp in the passport. It was at this time that my friend realized that the passport lacked an entry stamp of arrival through CBX. The officer explained that someone who intends to stay alone in San Diego ("until Del Mar" in his words) would not have to do this and that the same rule applies to CBX, so it would be normal for my friend to miss I-94 as the entry stamp.

The I-94 was issued, the passport was sealed and my friend entered the United States without problems.

However, I am publishing this question because in my experience of almost 30 years as a "user" of the United States Immigration System, I have never heard of this rule. A Google search of "I-94 land border" produces tons of publications on a different rule: the one that says you can enter through the land border with an expired visa using a valid I-94. Not applicable here

As a side note, all the Otay Mesa border personnel we interact with refer to I-94 as a "Permit" or "Permit," although I think that technically it is not the correct term. Very confusing.

TL; DR

What exactly is the rule that says that the holder of a tourist visa that enters through the land border and stays near the port of entry does not need an I-94 stamp and passport? What is the exact distance that the person can travel from the port of entry? What is the legal status of someone who has entered without a stamp and without I-94 under those rules?

litecoin – Problems connecting to my lighting network node on port 9735

I am in Windows 10. I am already successfully running a full Litecoin node. Disabling the Windows firewall has no effect on this problem.

I'm using litecoind-0.17.1 Y lnd-0.7.0-beta.

There are 2 things that I noticed:

2019-07-21 21: 24: 33.380 [INF] CMGR: Server listening on 127.0.0.1:1

and the error message:

2019-07-21 20: 32: 53.932 [ERR] SRVR: Can not connect to 028fdcc25bc8deeeaa087786b12560ec2c707f76795c1e8b4bda301ad3bea28ce9@X.X for example from: For what is in our content:

Is it okay for the server to be listening on port 1? And why can not I connect to my machine through port 9735 even if the port is open? Should I open a channel?

lnd.conf:

litecoin.active = 1
debuglevel = info
listen = 127.0.0.1: 9735
externalip = X.X.X.X
rpchost = 127.0.0.1
rpclisten = 0.0.0.0: 10009
restlisten = 0.0.0.0: 10010
tlsextraip = X.X.X.X

alias = XXXX
color = # fa00f0
maxpendingchannels = 10
litecoin.mainnet = 1
litecoin.active = 1

litecoin.node = litecoind
litecoind.rpchost = 127.0.0.1
litecoind.rpcuser = XXXXXXXXXX
litecoind.rpcpass = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
litecoind.zmqpubrawblock = tcp: //127.0.0.1: 29332
litecoind.zmqpubrawtx = tcp: //127.0.0.1: 29333

litecoin.conf:

server = 1
demon = 1
listen = 1
maxonections = 65
wait time = 5200
Mempoolexpiry = 340
addnode = 118.184.26.154
addnode = 112.74.50.226
addnode = 108.56.77.113
addnode = 144.76.238.49
addnode = 94.23.11.172
bantime = 345600
externalip = X.X.X.X

rpcallowip = 127.0.0.1

port = 9333
rpcport = 9332
testnet = 0
txindex = 1
rpcuser = XXXXXXXXX
rpcpassword = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
zmqpubrawblock = tcp: //127.0.0.1: 29332
zmqpubrawtx = tcp: //127.0.0.1: 29333
addresstype = p2sh-segwit
deprecatedrpc = signrawtransaction

Complete record of the lnd below:

2019-07-21 20: 32: 19.189 [INF] LTND: Version: 0.7.0-beta commit = v0.7.0-beta, build = production, logging = default
2019-07-21 20: 32: 19.190 [INF] LTND: Active chain: Litecoin (network = main network)
2019-07-21 20:32:19.200 [INF] CHDB: Checking the update of the scheme: latest_version = 9, db_version = 9
2019-07-21 20: 32: 19.220 [INF] RPCS: RPC server password listening on 0.0.0.0:10009
2019-07-21 20: 32: 19.223 [INF] RPCS: the password of the gRPC proxy started at 0.0.0.0:10010
2019-07-21 20: 32: 19.234 [INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet,` lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.
2019-07-21 20: 32: 23.019 [INF] LNWL: open wallet
2019-07-21 20: 32: 23.089 [INF] LTND: the main chain is set to: litecoin
2019-07-21 20: 32: 23.112 [INF] LNWL: started to listen to bitcoind blocking notifications via ZMQ at tcp: //127.0.0.1: 29332
2019-07-21 20: 32: 23.112 [INF] LTND: Initializing the tariff estimator backed by litecoind
2019-07-21 20: 32: 23.112 [INF] LNWL: started listening to bitcoind transaction notifications through ZMQ at tcp: //127.0.0.1: 29333
2019-07-21 20: 32: 24,800 [INF] LNWL: the wallet has been unlocked without a time limit
2019-07-21 20: 32: 24,810 [INF] LTND: LightningWallet opened
2019-07-21 20: 32: 25.073 [INF] HSWC: Restoring the state of the circuit in memory from the disk
2019-07-21 20: 32: 25.076 [INF] HSWC: Charged payment circuits: num_pending = 0, num_open = 0
2019-07-21 20: 32: 25.109 [INF] LTND: The backup proxy channel notifier is starting
2019-07-21 20: 32: 25.109 [INF] ATPL: Automatic execution of the autopilot with cfg: (* lnd.autoPilotConfig) (0xc000077480) ({
Active: (bool) false,
Heuristics: (map[string]float64) (len = 1) {
(string) (len = 12) "preferential": (float64) 1
}
MaxChannels: (int) 5,
Assignment: (float64) 0.6,
MinChannelSize: (int64) 20000,
MaxChannelSize: (int64) 16777215,
Private: (bool) false,
MinConfs: (int32) 0,
ConfTarget: (uint32) 3
})

2019-07-21 20: 32: 25.120 [INF] RPCS: RPC server listening on 0.0.0.0:10009
2019-07-21 20: 32: 25.120 [INF] RPCS: the gRPC proxy started at 0.0.0.0:10010
2019-07-21 20: 32: 25.124 [INF] LTND: Waiting for the chain to finish the synchronization, start_height = 1671547
2019-07-21 20: 32: 25,821 [INF] LNWL: started to be re-scanned from block cc29b974cece1cfc5917abd5d0f1d611f89b68098fa8b28e7fa9699b28d7a141 (height 1671544) for 0 addresses
2019-07-21 20: 32: 25,839 [INF] LNWL: Retrieving block hashes at height 1671547, this could take a while
2019-07-21 20: 32: 26.187 [INF] LNWL: Done to recover block hashes.
2019-07-21 20: 32: 26.187 [INF] LNWL: scan completed for 0 addresses (synchronized with block 4d54031a8a994c8d17ce7ef65646665e02ef753ae8d543da6d01828bf65d6eeb, height 1671547)
2019-07-21 20: 32: 27.132 [INF] LTND: the backend of the chain is completely synchronized (end_height = 1671547)!
2019-07-21 20: 32: 27.140 [INF] NTFN: New subscription to the block era
2019-07-21 20: 32: 27.140 [INF] HSWC: starting the HTLC switch
2019-07-21 20: 32: 27.252 [INF] NTFN: New subscription to the block era
2019-07-21 20: 32: 27.254 [INF] NTFN: New subscription to the block era
2019-07-21 20: 32: 27.256 [INF] NTFN: New subscription to the block era
2019-07-21 20: 32: 27.257 [INF] DISC: the authenticated Gossiper is starting
2019-07-21 20: 32: 27.258 [INF] BRAR: observer of contract of departure, monitoring for violations
2019-07-21 20: 32: 27.258 [INF] NTFN: New subscription to the block era
2019-07-21 20: 32: 27.266 [INF] CRTR: Starting FilteredChainView
2019-07-21 20: 32: 27.275 [INF] CRTR: Filtering chain using 0 active channels.
2019-07-21 20: 32: 27.276 [INF] CRTR: pruning tip for the channel graph: height = 1671544, hash = cc29b974cece1cfc5917abd5d0f1d611f89b68098fa8b28e7fa9699b28d7a141
2019-07-21 20: 32: 27.277 [INF] CRTR: Synchronize the channel graph from height = 1671544 (hash = cc29b974cece1cfc5917abd5d0f1d611f89b68098fa8b28e7fa9699b28d7ta)
2019-07-21 20: 32: 27.295 [INF] CRTR: Block e558b9153f30b1f217539fd094c5b9e55b84c52a64565f3e5e4a91b3b5ae4137 (height = 1671545) closed 0 channels
2019-07-21 20: 32: 27.307 [INF] CRTR: Block c3133127e12b7e96b3f0f7adfcf7ac199681e8b9f3d72024349a0d9c12a9c088 (height = 1671546) closed 0 channels
2019-07-21 20: 32: 27.315 [INF] CRTR: Block 4d54031a8a994c8d17ce7ef65646665e02ef753ae8d543da6d01828bf65d6eeb (height = 1671547) closed 0 channels
2019-07-21 20: 32: 27.315 [INF] CRTR: Full graphics cutout: 0 channels were closed from height 1671544
2019-07-21 20: 32: 27.332 [INF] CHBU: Starting chanbackup.SubSwapper
2019-07-21 20:32:27,338 [INF] CMGR: Server listening on 127.0.0.1:1
2019-07-21 20: 32: 27.341 [INF] SRVR: Initializing bootstrapers of the peer network!
2019-07-21 20: 32: 27,348 [INF] SRVR: Creating DNS bootstrapper with seeds: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 32: 27,342 [INF] CHBU: Update the backup file in C:  Users  root  AppData  Local  Lnd  data  chain  litecoin  mainnet  channel.backup
2019-07-21 20: 32: 27.363 [INF] DISC: Attempting to boot with: BOLT-0010 DNS Seed: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 32: 27.374 [INF] CHBU: Exchange the multiple backup file from C:  Users  root  AppData  Local  Lnd  data  chain  litecoin  mainnet  temp-dont-use.backup to C:  Users  root  AppData  Local  Lnd  data  string  litecoin  mainnet  channel.backup
2019-07-21 20: 32: 32.831 [INF] DISC: Attempting to boot with: Authenticated channel graph
2019-07-21 20: 32: 32.831 [INF] DISC: Obtained 1 addrs to start the network with
2019-07-21 20: 32: 37.933 [INF] DISC: Attempting to boot with: BOLT-0010 DNS Seed: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 32: 38.314 [INF] DISC: Attempting to boot with: Authenticated channel graph
2019-07-21 20: 32: 38.314 [ERR] SRVR: the initial start mates can not be recovered: no addresses were found
2019-07-21 20: 32: 42.319 [INF] DISC: Attempting to boot with: BOLT-0010 DNS Seed: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 32: 42.587 [INF] DISC: Attempting to boot with: Authenticated channel graph
2019-07-21 20: 32: 42.587 [ERR] SRVR: the initial start mates can not be recovered: no addresses were found
2019-07-21 20:32:50,594 [INF] DISC: Attempting to boot with: BOLT-0010 DNS Seed: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 32: 50.968 [INF] DISC: Attempting to boot with: Authenticated channel graph
2019-07-21 20: 32: 50.968 [ERR] SRVR: the initial start mates can not be recovered: no addresses were found
2019-07-21 20: 32: 53.932 [ERR] SRVR: Can not connect to 028fdcc25bc8deeeaa087786b12560ec2c707f76795c1e8b4bda301ad3bea28ce9@X.X for example from: For what is in our content:
2019-07-21 20: 33: 07.207 [INF] DISC: Attempting to boot with: Authenticated channel graph
2019-07-21 20: 33: 07.207 [INF] DISC: Attempting to boot with: BOLT-0010 DNS Seed: [[ltc.nodes.lightning.directory soa.nodes.lightning.directory]]2019-07-21 20: 33: 07.608 [ERR] SRVR: the initial start mates can not be recovered: no addresses were found
2019-07-21 20: 33: 20.551 [INF] LTND: Interruption received
2019-07-21 20: 33: 20.551 [INF] LTND: turning off ...
2019-07-21 20: 33: 20.556 [INF] LTND: Closing gracefully
2019-07-21 20: 33: 20.556 [INF] HSWC: Blocking the canceled time, the decomposed hash register goes out
2019-07-21 20: 33: 20.556 [INF] CRTR: FilteredChainView stopping
2019-07-21 20: 33: 20.557 [INF] HSWC: the HTLC switch goes off
2019-07-21 20: 33: 20.558 [INF] UTXN: UTXO daycare closing
2019-07-21 20: 33: 20.564 [INF] BRAR: Breach of arbitrator closing.
2019-07-21 20: 33: 20.578 [INF] DISC: Authenticated Gossiper is stopping
2019-07-21 20: 33: 20.581 [INF] CNCT: Stop the chain arsenal
2019-07-21 20: 33: 20.591 [INF] FNDG: Fund manager closing
2019-07-21 20: 33: 20.591 [INF] CHBU: Stopping chanbackup.SubSwapper
2019-07-21 20: 33: 20,603 [INF] RPCS: Stopping the RPC server
2019-07-21 20: 33: 20.618 [INF] RPCS: Stopping RouterRPC Sub-RPC Server
2019-07-21 20: 33: 20.620 [INF] RPCS: Stop SignRPC Sub-RPC Server
2019-07-21 20: 33: 20.636 [INF] RPCS: Stop AutopilotRPC Sub-RPC Server
2019-07-21 20: 33: 20,648 [INF] RPCS: Stop the ChainRPC Sub-RPC server
2019-07-21 20: 33: 20.658 [INF] RPCS: Stop InvoicesRPC Sub-RPC Server
2019-07-21 20: 33: 20.672 [INF] RPCS: Stop the WalletKitRPC Sub-RPC server
2019-07-21 20: 33: 20.675 [INF] RPCS: Stopping the WatchtowerRPC Sub-RPC server
2019-07-21 20: 33: 20.682 [INF] LTND: Complete closure

Ask about how to try to port a C # to C ++ function Nintendo DS

Recently I found an application of homemade NDS that lacks a feature of the PC version of that program. I wanted to test and port this feature in the NDS version. The only problem is that the PC version is written in C #, and NDS is C ++. Any easy way to do this? Thank you.

I am using GlassFish with Inellij and when I create a project I get "Error: the configuration of the administration port was not found"

I've searched Google for this problem and found these questions in the OverFlow stack https://stackoverflow.com/questions/7010418/admin-port-configuration-not-found-error-while-setting-up-glassfish-config-in- i
Y
https://stackoverflow.com/questions/24639989/intellij-idea-13-and-glassfish-4-integration-error-admin-port-configuration-n?rq=1
I have read both answers and I still do not know what to do.
I have checked the folder C: glassfish3 glassfish config on my computer, it does not have the file domain.xml in it.

Is the missing file the problem? Enter the description of the image here.
enter the description of the image here

security – Securing Admin in a separate port

I am trying to secure the administration pages (/ admin / *) and the login page (/ user / login) to port 8443. I have done this successfully with the following in apache 2.4:


    
    
    
    ServerName example.com:443
ServerAlias ​​drupal
DocumentRoot "/opt/rh/httpd24/root/var/www/html/example.com/current"
    
            Require everything denied
    



    
    
    
    ServerName example.com:8443
ServerAlias ​​drupal
DocumentRoot "/opt/rh/httpd24/root/var/www/html/example.com/current"

The problem I have is when I go to https://www.example.com:8443/user/login and login, I am redirected to http://www.example.com:8443/user/1.

This creates an error 400 – Incorrect request. Trying to serve http content through an SSL port.

How do I tell drupal to stay on the https protocol and stay on port 8443?

Ruby on Rails: port 3000 can not be accessed on the LAN

I'm on Ubuntu 16.0
Running Ruby on Rails with the webric server as:
enter the description of the image here

I have opened the ports as:
enter the description of the image here

to open the port I used the ufw command as:
sudo ufw allows 3000 / tcp
My Lan Ip is like
enter the description of the image here

But if I access port 3000 from another system on the same LAN:
shows that the site can not be reached
I access my website as:
192.168.2.100:3000
But I can access the apache that runs on port 80.
So, can I access the application that runs on port 3000? If yes, suggest what should be done, thanks in advance

mobile – Random port open on my phone?

I did a port scan on my phone to see if it had open ports,
Normally I do not have any open port
Until I realized …

The port (32772 sometimes-rpc7) was open for some reason? Any clue what is this service for? I can not find out what services are using it and why it is there.
Do I have something to worry about?
It just appeared at random.

If someone can shed some light I would be very grateful.

regtest – bitcoin-cli does not use the port specified in config

I have configured a bitcoin node in regtest mode with custom configuration and datadir.

Start bittcoind with the command:

    bitcoind -conf = bitcoin-demo.conf -regtest -datadir = "testdatabtc" -daemon

My bitcoin-demo.conf looks like:

regtest = 1
server = 1
rpcuser = alice
rpcpassword = hello
rpcallowip = 0.0.0.0 / 0
rpcconnect = 127.0.0.1
# Options only for regtest
[regtest]
rpcport = 3133

I can connect access to my node using the curl command

curl - user alice: hello --data & # 39; {"method": "getblockchaininfo", "params":[], "id": 1, "jsonrpc": "2.0"} -H - "Content-Type: application / json" -X POST http: // localhost: 3133

But when I try to access the same commands using bitcoin-cli, try to connect to port 8332, even when specifying the configuration file.

bitcoin-cli -conf = "bitcoin-demo.conf" getblockchaininfo

This command produces error:

Error: Unable to connect to server 127.0.0.1:8332

This works if I specify the port and authentication as a command line argument:

bitcoin-cli -conf = "bitcoin-demo.conf" -rpcport = "3133" -rpcuser = "alice" -rpcpassword = "hello" getblockchaininfo

The above command works fine. But the question is

Why does not bitcoin-cli read these arguments from the configuration file?

linux – Serial port library for C unix systems using the callback model

I wrote a block serial port library, the C port serial library lock, but I prefer no blocking, so I wrote this library where the user can specify callbacks. So it's an event driven.

The code assumes C99 or better. How could this be improved?

The example is quite personalized to work in the UK with the British Telecom caller ID system: https://www.btplc.com/SINet/sins/pdf/242v2p5.pdf

serial_port.h:

/ * Serial port library for unix platform.
It uses the Unix selection method and callbacks are used to notify events.
The supported events are connection and readings.
The user must provide connected and / or read callback functions for
Notified of these events.
Author: angus comber
* /
#ifndef SERIAL_PORT_H_
# define SERIAL_PORT_H_

# define READ_BUFFERSIZE 100

#include   // size_t

/ * opaque serial port object * /
struct serial_port;
typedef struct serial_port serial_port_t;

// callbacks defined by the user
typedef void (* connect_callback) (serial_port_t * port, void * userdata);
typedef void (* read_callback) (serial_port_t * port, char * buffer, int * length, void * userdata);

/ * port_start opens the port name in baudrate.
Return immediately with the error code -1 in case of not opening the port. Question
errno for more information. Alternatively, if you can not allocate memory for
the port object returns -2 error.
If the port configuration continues successfully, port_start is blocked until the process is closed.
Arguments:
- port name - port identifier for modem
- Baud rate - Connection speed
- connectcb - callback defined by the user in a successful connection that is being established
- readcb - callback defined by the user when reading data on the port
- userdata - user-defined data to switch to callback functions (can be NULL)
* /
int port_start (const char * port name, const int baudrate, connect_callback connectcb, read_callback readcb, void * userdata);

/ * returns written characters or -1 in error * /
int port_write (serial_port_t * port, const char * data, size_t length);
/ * returns characters read or -1 in error * /
int port_read (serial_port_t * port, char * buffer, int buffer_size);
/ * close port and release assigned resources * /
int port_close (serial_port_t * port);

#endif // SERIAL_PORT_H_

serial_port.c:

/ * serial port class for unix platform using callbacks * /
#include "serial_port.h"

#include   // posix api
#include    // file control operations
#include  // terminal

struct serial_port {
int fd;
int baudrate;
struct termios restore_tty;
struct termios current_tty;
connect_callback connectcb;
read_callback readcb;
void * userdata;
};

static int set_speed (struct termios tty, int speed) {
speed_t sp;
switch (speed) {
case 1200: sp = B1200; break;
case 1800: sp = B1800; break;
case 2400: sp = B2400; break;
case 4800: sp = B4800; break;
case 9600: sp = B9600; break;
case 19200: sp = B19200; break;
case 38400: sp = B38400; break;
case 57600: sp = B57600; break;
case 115200: sp = B115200; break;
default: return -1; // not supported
}

int baudset = cfsetospeed (& tty, sp);
baudset = cfsetispeed (& tty, sp);
return baudset;
}

static int get_term (int fd, struct termios * ptty) {
/ * Upon successful completion, 0. will be returned. Otherwise, -1
will be returned and errno configured to indicate the error. * /
returns tcgetattr (fd, ptty);
}

/ * configure tty * /
static int set_terminal (int fd, struct termios * ptty) {
ptty-> c_cflag | = (CLOCAL | CREAD); / * ignore the modem controls * /
ptty-> c_cflag & = ~ CSIZE;
ptty-> c_cflag | = CS8; / * 8-bit characters * /
ptty-> c_cflag & = ~ PARENB; / * no parity * /
ptty-> c_cflag & = ~ CSTOPB; / * only needs 1 stop bit * /
ptty-> c_cflag & = ~ CRTSCTS; / * there is no hardware flow control * /

/ * configuration for non-canonical mode * /
ptty-> c_iflag & = ~ (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
ptty-> c_lflag & = ~ (ECHO | ECHONL | ICANON | ISIG | IEXTEN);
ptty-> c_oflag & = ~ OPOST;

/ * look for bytes as they become available * /
ptty-> c_cc[VMIN] = 1;
ptty-> c_cc[VTIME] = 1;

if (tcsetattr (fd, TCSANOW, ptty)! = 0) {
// Error of tcsetattr- use strerror (errno)
returns -1;
}
returns 0;
}

int port_start (const char * port name, const int baudrate, connect_callback connectcb, read_callback readcb, void * userdata) {
// open in non-blocking mode and notify as readings and complete writing through callbacks
int fd = open (port name, O_RDWR | O_NOCTTY | O_NONBLOCK);
yes (fd == -1) {
returns -1;
}
serial_port_t * port = malloc (sizeof (serial_port_t));
if (port) {
port-> fd = fd;
port-> transmission speed = transmission speed;
port-> connectcb = connectcb;
port-> readcb = readcb;
port-> userdata = userdata;

// cache the configuration of the previous terminal to restore later
if (get_term (port-> fd, & port-> current_tty) == 0) {
// previous tty configuration cache
port-> restore_tty = port-> current_tty;
} else {
returns -1;
}
// set the port speed
if (set_speed (port-> current_tty, port-> baudrate) == -1) {
// error when setting the speed tty
returns -1;
}
// set terminal attributes
if (set_terminal (port-> fd, & port-> current_tty) < 0) {
            // error configuring port
            return -1;
        }
    } else {
        return -2;
    }

    if(port->connectcb) {
connectcb (port, userdata);
}

fd_set readset;

// keep on looping forever
while (1 == 1) {
FD_ZERO (& readset); / * Delete the set * /
FD_SET (fd, & readset); / * add our file descriptor to the set * /

// wait for the data to be read (infinite waiting time)
int rv = select (fd + 1, & readset, NULL, NULL, NULL);
if (rv> 0) {// we have activity
// only works with a fd, so there's no need to loop
for (int i = fd; i < fd + 1; ++i) {
                if(FD_ISSET(fd, &readset)) {
                    if(readcb) {
                        char data[READ_BUFFERSIZE];
                        int len = READ_BUFFERSIZE;
                        int bytes_read = port_read(port, data, len);
                        readcb(port, data, &bytes_read, userdata);
                    }
            }
        }
        // if an error occurred, exit
        } else {
            return -1;
        }
    }  // while
}

int port_write(serial_port_t* port, const char* data, size_t length) {
    return write(port->fd, data, length);
}

int port_read (serial_port_t * port, char * buffer, int buffer_size) {
return reading (port-> fd, buffer, buffer_size);
}

int port_close (serial_port_t * port) {
if (tcsetattr (port-> fd, TCSANOW, and port-> restore_tty) < 0) {
        // error restoring attributes
    }
    int result = close(port->fd);
Free port);
return result
}

C Main:

#include 
#include 
#include   // strerror
#include    // errno
#include    // isprint

#include "serial_port.h"

enumeration {RESET, SETCOUNTRY, SETCALLERID, WAITFORCALL};

/ * getline_string function args:
buffer - buffer to fill with line
size - ptr to the size of the line or -1 if no line is drawn
source - source of bytes
end - end of the byte stream
returns the remaining string flow or NULL if at the end of the string flow
* /
static const char * getline_stringstream (char * line, int * size, const char * source, const char * end) {
const char * s = source;
char * t = line;
* size = 0;

// eat any new line added
while (s! = end && * s && (* s == & # 39;  r & # 39; || s == & # 39;  n & # 39;))
s ++;

while (s! = end && * s && * s! = & # 39;  r & # 39; && * s! = & # 39;  n & # 39;) {
* t ++ = * s ++;
(* size) ++;
}
* t = & # 39;  0 & # 39 ;; // null termination string
return * size> 0? s: NULL;
}

/ * in a successful connection we print the report header * /
connected void (port serial_port_t *, void * userdata) {
printf ("% - 6s% -6s% s  n", "Date", "Time", "Caller ID");
port_write (port, "AT  r  n", 4);
}

/ * use the simple state machine to configure the modem and when finished, send the caller ID * /
void readdata (port serial_port_t *, char * buffer, int * length, void * userdata) {
enum stage * step = userdata;
switch (* step) {
RESET case:
port_write (port, "ATZ  r  n", 5); // restart modem
* step = SETCOUNTRY;
break;
SETCOUNTRY case:
port_write (port, "AT + GCI = B4  r  n", 11); // set the country in the United Kingdom
* step = SETCALLERID;
break;
SETCALLERID case:
port_write (port, "AT + VCID = 1  r  n", 11); // enable formatted call reporting
* step = WAITFORCALL;
break;
WAITFORCALL case:
{
// analyze the call data in the caller ID, etc.
static char callid[50] = {0};
static char caller_date[20] = {0};
static char caller_time[20] = {0};

int size
char line[100]; // We assume that there are no lines> 100 characters
const char * rest = buffer;
char * end = buffer + * length;
while ((rest = getline_stringstream (line, & size, rest, end))! = NULL) {
if (strncmp (line, "NMBR", 4) == 0 && strlen (line)> 7) {
strcpy (callerid, & line[7]);
}
if (strncmp (line, "DATE", 4) == 0 && strlen (line)> = 11) {
sprintf (caller_date, "% c% c /% c% c", line[9]line[10]line[7]line[8]);
}
if (strncmp (line, "TIME", 4) == 0 && strlen (line)> = 11) {
sprintf (caller_time, "% c% c:% c% c", line[7]line[8]line[9]line[10]);
}
}
if (strlen (callerid)> 0 && strlen (caller_date)> 0 && strlen (caller_time)> 0) {
printf ("% - 6s% -6s% s  n", caller_date, caller_time, callerid);
caller ID[0] = caller_date[0] = caller_time[0] = & # 39;  0 & # 39 ;;
}
}
break;
default:
fprintf (stderr, "something unexpected happened, aborting ...  n");
fflush (stdout);
exit (1); // something bad happened - coming out
}
}

// test the serial library with modem
int main (int argc, char * argv[]) {

yes (argc! = 3) {
printf ("Use:% s   n ", argv[0]);
exit (EXIT_FAILURE);
}

const char * portname = argv[1];
const int baudrate = atoi (argv[2]);
step of the enumeration stage = RESET;

// the program will be blocked here forever
if (port_start (port name, baud rate, connected, read data, and step) == -1) {
fprintf (stderr, "An error occurred when starting serial port connection in% s, error:% s  n", port name, strerror (errno));
}
}

Example of output below.

acomber @ mail: ~ / Documents / projects / modem / serial / serial_port_select_lib $ sudo ./prog / dev / ttyACM0 9600
Date and time caller ID
08/07 10:43 07766112233
07/08 10:47 P
08/07 10:48 07766123123

At the next exit, the second call at 10:47, had the caller ID hidden and, therefore, the character P is the string indicating PRIVATE.