Network Programming With Rust 1st Edition Abhishek Chanda pdf download
Network Programming With Rust 1st Edition Abhishek Chanda pdf download
https://textbookfull.com/product/network-programming-with-
rust-1st-edition-abhishek-chanda/
https://textbookfull.com/product/programming-webassembly-with-
rust-1st-edition-kevin-hoffman/
https://textbookfull.com/product/programming-rust-1st-edition-
jim-blandy/
https://textbookfull.com/product/the-rust-programming-language-
covers-rust-2018-steve-klabnik/
https://textbookfull.com/product/learning-network-programming-
with-java-1st-edition-reese-richard-m/
The Rust Programming Language 1st Edition Steve Klabnik
https://textbookfull.com/product/the-rust-programming-
language-1st-edition-steve-klabnik/
https://textbookfull.com/product/asynchronous-programming-in-
rust-1st-edition-carl-fredrik-samson/
https://textbookfull.com/product/practical-network-automation-
leverage-the-power-of-python-and-ansible-to-optimize-your-
network-1st-edition-abhishek-ratan/
https://textbookfull.com/product/programming-rust-2nd-edition-
early-release-jim-blandy/
https://textbookfull.com/product/the-rust-programming-
language-2nd-edition-steve-klabnik/
Network Programming with
Rust
Abhishek Chanda
BIRMINGHAM - MUMBAI
Network Programming with Rust
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations
embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented.
However, the information contained in this book is sold without warranty, either express or implied. Neither the
author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to
have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy
of this information.
ISBN 978-1-78862-489-3
www.packtpub.com
To my wife, Anasua, for being an amazing partner and friend, and also for all the diagrams in
this book.
To the memory of my mother, Sikha, for her sacrifices and for exemplifying the power of
determination.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.
Contributors
I would like to thank Packt and their wonderful team for making this possible, especially
Vikas, Chaitanya, Madhunikita, and Diwakar. I am grateful to Pradeep and all the
reviewers for their insightful comments. This book would not have been possible without
the support of my wife, Anasua.
About the reviewer
Pradeep R is a software professional at Gigamon. He is a technology enthusiast passionate
about network programing and security, with wide experience in working on leading
enterprise network switching and routing solutions and in development and deployment of
traditional network security elements. Currently, he is working on next-generation network
pervasive visibility solutions.
He extensively works with C, C++, Python, JavaScript, Perl, and occasionally with Java,
.NET, and Rust. Pradeep has recently reviewed Rust Cookbook.
I would like to thank Vigneshwer Dhinakaran, my brother, who has shown me that
boundaries exists only in our minds and they are meant to be breached. I would also like to
acknowledge with gratitude my mother, Vasanthi, my grandma, Sulochana, and my sister,
Deepika, for their constant encouragement and support.
[ ii ]
Table of Contents
Index 258
[ iii ]
Preface
Rust has steadily become one of the most important new programming languages in recent
years. Like C or C++, Rust enables the developer to write code that is low-level enough to
make Rust code quickly. And since Rust is memory-safe by design, it does not allow code
that can crash on a null pointer exception. These properties make it a natural choice for
writing low-level networking applications. This book will enable developers to get started
with writing networking applications with Rust.
Chapter 2, Introduction to Rust and its Ecosystem, contains an introduction to Rust. This is an
overall introduction that should be good enough to get the reader started. We do assume
some familiarity with programming.
Chapter 3, TCP and UDP Using Rust, dives into using Rust for networking. We start with
basic socket programming using the standard library. We then look at some crates from the
ecosystem that can be used for network programming.
Chapter 4, Data Serialization, Deserialization, and Parsing, explains that an important aspect
of networked computing is handling data. This chapter is an introduction to serializing and
deserializing data using Serde. We also look at parsing using nom and other frameworks.
Chapter 5, Application Layer Protocols, moves up a layer to look at protocols that operate
above TCP/IP. We look at a few crates to work with, such as RPC, SMTP, FTP, and TFTP.
Preface
Chapter 6, Talking HTTP in the Internet, explains that arguably the most common
application of the internet is HTTP. We look at crates such as Hyper and Rocket which are
used for writing HTTP servers and clients.
Chapter 7, Asynchronous Network Programming Using Tokio, looks at the Tokio stack for
asynchronous programming using futures, streams, and event loops.
Chapter 8, Security, delves into securing the services we have described so far. This is using
certificates and secret keys.
Chapter 9, Appendix, discusses a number of crates have appeared that propose alternate
ways of doing things already covered in this book. This includes the async/await syntax,
parsing using Pest, and so on. We will discuss some of these in the appendix.
[2]
Preface
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/
PacktPublishing/Network-Programming-with-Rust. We also have other code bundles from
our rich catalog of books and videos available at https://github.com/PacktPublishing/.
Check them out!
Conventions used
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "The target directory contains compilation artifacts."
Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example: "It
will not need to call connect for that same connection:"
[3]
Preface
Get in touch
Feedback from our readers is always welcome.
General feedback: Email feedback@packtpub.com and mention the book title in the
subject of your message. If you have questions about any aspect of this book, please email
us at questions@packtpub.com.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit www.packtpub.com/submit-errata, selecting your book,
clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at copyright@packtpub.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!
[4]
Introduction to Client/Server
1
Networking
This book is an introduction to writing networking applications in Rust. This title begs two
questions: why should anyone care about networking? And why would anyone want to
write networking applications in Rust? We attempt to answer the first question in this
chapter. We will introduce Rust and network programming using Rust in subsequent
chapters. Firstly, in this chapter, we will start with a bit of history and try to understand
how network architecture evolved over the last hundred years. In subsequent sections, we
will see how modern networks are layered and addressed. Afterwards, we will describe
common service models used in networking. We will end with a summary of networking-
related programming interfaces that Linux exposes. Note that this book deliberately ignores
network programming in other operating systems and focuses only on Linux for the sake of
simplicity. While the Rust compiler is platform-agnostic, there can be cases where some
things are different in other platforms compared to Linux. We will point out those
differences as we progress.
History of networking: why and how networks came into use and how the
internet evolved
Layering in networks: how layering and encapsulation works
Addressing: how networks and individual hosts are uniquely identified on the
internet
How IP routing works
How DNS works
Service models for data delivery
The network programming interface in Linux
Introduction to Client/Server Networking Chapter 1
Since networks evolved in silos all around the world, they were often organized according
to geographical proximity. A Local Area Network (LAN) is a collection of host machines in
small proximity like a building or a small neighborhood. A Wide Area Network (WAN) is
one that connects multiple neighborhoods; the global internet is at the top of the
hierarchy. The next picture shows a map of the ARPANET in 1977. Each node in this map is
a computer (a server, in today's terms). Most of these were located in large universities like
Stanford or at national laboratories like Lawrence Berkeley (source: https://commons.
wikimedia.org/wiki/File:Arpanet_logical_map,_march_1977.png).
[6]
Introduction to Client/Server Networking Chapter 1
Layering in networks
Computer science often focuses on subdividing a problem into smaller, hopefully
independent components that can be solved in isolation. Once that is done, all that is
needed is a set of rules on how those components should communicate to have a solution to
the larger problem. This set of rules, along with a pre-agreed data format, is called a
protocol. A network is composed of a number of layers, each of which has a fixed purpose.
Thus, each of these layers run one or many protocols, forming a stack of protocols. In the
early days of networking, different people implemented their networks in different ways.
When the internet was conceived, there was a need to make these networks communicate
seamlessly. Since they were constructed differently, this turned out to be difficult.
[7]
Introduction to Client/Server Networking Chapter 1
There was a clear need to agree on standard protocols and interfaces to make the internet
work. The first attempt at standardizing networking protocols was in 1977, which led to the
OSI model. This model has the following layers:
The following figure shows a visual representation of this model (source: https://commons.
wikimedia.org/wiki/File:Osi-model-jb.svg). This also shows two vertical classifications,
the host running the network stack and the physical media (including the wire and the
network device). Each layer has its own data unit, the representation of the information it
works on, and since each layer encapsulates the one below it, the data units encapsulate too.
A number of bits form a frame, a number of frames form a packet, and so on, to the top:
[8]
Introduction to Client/Server Networking Chapter 1
While OSI was working on standardizing this model, Defense Advanced Research Projects
Agency (DARPA) came up with a full implementation of the much simpler TCP/IP model
(also known as the IP (Internet Protocol) suite). This model has the following layers, from
closest to the physical medium to the farthest:
Hardware interface layer: This is a combination of layers one and two of the OSI
model. This layer is responsible for managing media access control, handling
transmission and reception of bits, retransmission, and coding (some texts on
networking differentiate between the hardware interface layer and the link layer.
This results in a five layer model instead of four. This hardly matters in practice,
though.)
IP layer: This layer corresponds to layer three of the OSI stack. Thus, this layer is
responsible for two major tasks: addressing hosts and networks so that they can
be uniquely identified and given a source and a destination address, and
computing the path between those given a bunch of constraints (routing).
Transport layer: This layer corresponds to layer four of the OSI stack. This layer
converts raw packets to a stream of packets with some guarantees: in-order
delivery (for TCP) and randomly ordered delivery (for UDP).
[9]
Introduction to Client/Server Networking Chapter 1
Application layer: This layer combines layers five to seven of the OSI stack and is
responsible for identifying the process, data formatting, and interfacing with all
user level applications.
Note that the definition of what a particular layer handles changes as we move from one
layer to another. The hardware interface layer handles collection of bits and bytes
transmitted by hosts, the IP layer handles packets (the collection of a number of bytes sent
by a host in a specific format), the transport layer bunches together packets from a given
process on a host to another process on another host to form a segment (for TCP) or
datagram (for UDP), and the application layer constructs application specific
representations from the underlying stream. For each of these layers, the representation of
data that they deal with is called a Protocol Data Unit (PDU) for that layer. As a
consequence of this layering, when a process running on a host wants to send data to
another host, the data must be broken into individual chunks. As the chunk travels from
one layer to another, each layer adds a header (sometimes a trailer) to the chunk, forming
the PDU for that layer. This process is called encapsulation. Thus, each layer provides a set
of services to layers above it, specified in the form of a protocol.
The modern internet exhibits a form of geographical hierarchy. Imagine a number of homes
which are served by a number of Internet Service Providers (ISPs). Each of these homes
is in a LAN (either via Ethernet, or more commonly, Wi-Fi). The ISP connects many such
LANs in a WAN. Each ISP has one or many WANs that they connect to form their own
network. These larger networks, spanning cities, which are controlled by a single business
entity, are called Administrative Systems (AS). Routing between multiple ISPs is often
more complex than regular IP routing since they have to take into account things like
trading agreements and so on. This is handled by specialized protocols like the Border
Gateway Protocol (BGP).
As mentioned before, one of the earliest and most successful networking technologies is
Ethernet. First introduced in 1974, it quickly became the predominant technology for LAN
and WAN due to its low cost and relative ease of maintenance. Ethernet is a shared media
protocol where all the hosts must use the same physical medium to send and receive
frames. Frames are delivered to all hosts, which will check if the destination MAC address
(these addresses will be described in the next section) matches its own address. If it does,
the frame is accepted, otherwise, it is discarded. Since the physical medium can only carry
one signal at any given moment, there is a probability that frames might collide in transit. If
that does occur, the sender can sense the collision by sensing transmission from other hosts
while it is transmitting its frame. It then aborts the transmission and sends a jam signal to
let other hosts know of the collision. Then, it waits for an exponentially backed off amount
of time and retries the transmission. After a fixed number of attempts, it gives up if the
transmission does not succeed.
[ 10 ]
Introduction to Client/Server Networking Chapter 1
This scheme is called carrier-sense multiple access with collision detection (CSMA/CD).
One problem with Ethernet is its relatively short range. Depending on the physical wiring
technology used, the maximum length of an Ethernet segment varies between 100 m to 500
m. Thus, multiple segments must be connected to form a larger network. The most common
way of doing that is using layer two switches between two adjacent Ethernet segments.
Each port of these switches forms different collision domains, reducing the overall
probability of collisions. These switches can also monitor traffic to learn which MAC
addresses are on which ports so that eventually, they will send out frames for that MAC
address only on that port (referred to as a learning switch). In modern homes, Wi-Fi is often
the dominant LAN technology compared to Ethernet.
Addressing in networks
We have seen why it is important to identify hosts and networks uniquely to be able to
deliver packets reliably. Depending on the scale, there are three major ways of doing this;
we will discuss each of those in this section. The end to end process of IP routing will be
discussed in the next section. One interesting fact to note is that for each of these addressing
modes, one or more addresses are reserved for special use. Often, these are marked by a
known set of bits being on or off in a known pattern:
Ethernet address: This is also known as a Media Access Control (MAC) address.
It is a 48-bit long unique identifier assigned to a network device (usually stored
on the card) that is used to identify it in a network segment. Usually, these are
programmed by the network card manufacturer, but all modern OS's allow one
to modify it. The standard way of writing Ethernet addresses are in six groups of
two hexadecimal digits (01-23-45-67-89-ab-cd-ef). Another common way is to use
a colon to separate the digits (01:23:45:67:89:ab:cd:ef). A few special sequences of
bits are reserved for addressing special cases: the sender can request that an
Ethernet frame should be received by all hosts in that segment by setting the least
significant bit of the first octet to 1; this is called multicasting. If that particular bit
is set to 0, the frame should be delivered to only one receiver. Today, these are
used widely with Ethernet and Wi-Fi.
[ 11 ]
Introduction to Client/Server Networking Chapter 1
Apart from these, communication between hosts often uses a port number to distinguish
between processes. When the OS allocates a specific port to a process, it updates its
database of the mapping between process identifier and port number. Thus, when it
receives incoming packets on that port, it knows what process to deliver those packets to. In
case the process has exited by that time, the OS will drop the packets and in the case of TCP,
initiate closing of the connection. In the subsequent sections, we will see how TCP works in
practice.
A range of port numbers between 0 and 1024 are reserved for common
services by the OS. Other applications are free to request any port above
1024.
[ 12 ]
Introduction to Client/Server Networking Chapter 1
[ 13 ]
Introduction to Client/Server Networking Chapter 1
There are two broad classes of IP address; some blocks of addresses can be routed in the
public internet, these are called public IP addresses. Some other blocks can only be used in
private networks that do not directly interface with the internet, these are called private
addresses. If a router on the internet receives a packet that is destined for a private IP
address, it will have to drop that packet. Other than these two, IP addresses are also
classified on various parameters: some are reserved for documentation only (192.0.2.0/24),
some are reserved for point to point communication between two hosts (169.254.0.0/16), and
so on. The Rust standard library has convenience methods to classify IP addresses
according to their types.
All routers maintain a routing table which maps prefixes to the outgoing interface of the
router (while a router administrator might decide to store individual addresses instead of
prefixes, this will quickly lead to a large routing table in a busy router). An entry in the table
basically says If a packet needs to go to this network, it should be sent on this interface. The next
host that receives the packet might be another router or the destination host. How do
routers figure out this table? Multiple routers run routing protocols between those which
compute those tables. Some common examples are OSPF, RIP, and BGP. Given these
primitives, the actual routing mechanism is fairly simple, as shown in the next diagram.
An interesting aspect of IP is the use of the Time To Live (TTL) field, this is also known as
hop limit. The host sends out packets with a fixed value of TTL (usually 64). Each router the
packet crossed decreases the TTL. When it reaches 0, the packet is discarded. This
mechanism ensures that packets are not stuck in an infinite loop between routers:
[ 14 ]
Introduction to Client/Server Networking Chapter 1
Note that while trying to match the prefix to routes in the routing table, multiple routes
might match. If that happens, the router must select the most specific match and use that for
forwarding. Since the most specific routes will have the maximum number of leading 1s,
and hence the largest prefix, this is called the longest prefix match. Say our router has the
following routing table, as shown in the diagram. eth1, eth2, and eth3 are three network
interfaces attached to our router, each having a different IP address in different networks:
At this point, if our device gets a packet that has a destination address set to 192.168.1.33, all
three prefixes have this address but the last one is the largest of the three. So, the packet will
go out through eth3.
A lot of what we described so far about IPv4 addresses does not change for IPv6, except, of
course, it has a larger address space of 128 bits. In this case, the length of the network mask
and the host mask depends on the address type.
One might be wondering, how do routers construct the routing table? As always, there are
protocols to help with that. Routing protocols are of two major types: interior gateway
protocols which are used for routing inside an autonomous system, and exterior gateway
protocols which are used in routing between autonomous systems; an example of the latter
is BGP. Interior gateway protocols can again be of two types, depending on how they look
at the whole network. In link state routing, each router participating in the protocol
maintains a view of the whole network topology. In distance vector routing, each router
only knows about its one hop neighbors. An example of the former is the Routing
Information Protocol (RIP) and of the latter is Open Shortest Path First (OSPF). Details
about these are beyond the scope of this book. However, we can note that the common
theme among all the routing protocols is that they work by exchanging information
between routers. Thus, they have their own packet formats for encapsulating that
information.
[ 15 ]
Introduction to Client/Server Networking Chapter 1
An application that needs to resolve a name will use a system call like getaddrinfo. This
essentially asks the OS to go ahead and resolve the name. This step is not shown in the
figure. The next steps are as follows:
1. Typically, each computer in a network will have a local DNS server configured in
the file /etc/resolv.conf. In most cases, this points to the ISP's DNS server.
This might also point to the home Wi-Fi router's DNS server. In that case, the
DNS will transparently proxy requests to the ISP's DNS server. The OS will then
query that server, asking the IP of the given name www.google.com.
[ 16 ]
Introduction to Client/Server Networking Chapter 1
2. The local DNS server will, in turn, ask the same question to a pre-populated list
of root name servers. These servers are maintained by ICANN and their
addresses are well-known. They maintain addresses for the top level domain
name servers. This means that they know the addresses of namesevers for the
.com domain.
3. In this step, the root name server replies with the addresses of TLD name servers
for the .com domain. These servers maintain a list of addresses for name servers
in their own domains.
4. The local DNS server then contacts one of those and asks the same question.
5. The TLD name server replies back with the addresses of servers in the
google.com domain. An admin of the google.com domain maintains a bunch
of nameservers for that domain. Those nameservers have full authority over all
records in that domain, and each of those records are marked authoritative to
indicate that.
6. The local DNS server then asks one of those the same question.
7. (Hopefully) that server does know the address of www.google.com. If it does, it
prepares a response, marks it as authoritative, and sends it back to the local DNS
server. The answer can also have a time to live associated with it so that the local
DNS server can cache it for future use and evict it after the given time is over. If it
does not, name resolution will fail and it will send back a special response called
NXDOMAIN.
8. The local DNS server then sends back the same response to the OS, which
delivers it to the application. The local server marks the response as non-
authoritative, indicating that it got that answer from somewhere else.
Interestingly, DNS is like asking a friend for someone's address, who then says I do not
know, but I know someone who knows someone who knows someone who might know. I can find out
for you! They then go and ask around and return with a reply.
DNS packets are often very small since they have a small question and answer along with
some control information, and since DNS does not need very high reliability from the
transport layer, this makes it an ideal candidate for using UDP (described in the next
section). However, most implementations include an option to fall back to TCP if the
transport is too unreliable.
[ 17 ]
Introduction to Client/Server Networking Chapter 1
DNS supports multiple record types for various things. The A record maps
a name to an IPv4 address, AAAA record maps a name to a IPv6 address,
and so on. Reverse lookups are supported using PTR records.
Connection-oriented service
The service a protocol provides to its consumers is connection oriented when each party
involved negotiates a virtual connection before sending the actual data. During the setup
process, a number of parameters about the connection must be agreed upon. This is
analogous to the older wired telephone systems, where a dedicated connection is set up
between the two hosts. In modern networks, an example is TCP. The PDU for TCP is a
segment, which consists of a header and a data section. The header has a few fields which
are used to transition between states of the protocol state machine. The next figure shows
what the TCP header looks like in practice. Each of the rows in this figure are of 32 bits
(thus, each row is two octets), and some are divided into multiple segments:
[ 18 ]
Introduction to Client/Server Networking Chapter 1
We will look at a few of these which are used for manipulating the connection between
hosts:
Control bits (flags) are a set of 9 bits that are used for various purposes. The flags
of interest here are SYN, ACK, FIN, and RST. SYN triggers a synchronization of
sequence numbers. The ACK flag indicates that the receiver should care about the
corresponding acknowledgment number. The FIN flag starts the process of
tearing down a connection. The RST flag resets the connection in case of an error.
The sequence number is a 32-bit field which is used to reorder messages at the
receiver. When the SYN flag is set (which should be the case only for the first
packet in a connection), the sequence number is the initial sequence number;
otherwise, it is the sequence number accumulated so far.
The acknowledgement number is a 32-bit field which is used to enable reliable
delivery of messages. If the ACK flag is set, this value is the next sequence
number that the sender is expecting.
Before two hosts running TCP can start exchanging data, they must do a three-way
handshake to establish a connection. This works like this: the client that wants to initiate
communication sends a SYN packet to the server. The sequence number is set to a random
value and the SYN flag is set to 1. The server responds with a packet that has both SYN and
ACK set to 1. This packet has the acknowledgment number set to one more than what it got
from the client, and the sequence number is set to a random number. Finally, the client
responds with a packet that has the ACK flag set, the sequence number set to the received
acknowledgement number in the last step, and the acknowledgement number is set to one
more than the sequence number in the previous step. After this is done successfully, both
the client and the server have agreed on sequence and acknowledgement numbers. The
advantage of this model is that is has a reliable connection where both the sender and the
receiver knows what to expect. The sender can tune the rate of sending data, depending on
how fast or slow the receiver is or how congested the network is. The disadvantage here is
the higher connection setup costs. Assuming it takes 100 ms to send a packet to a host in
another continent, we will need to exchange at least 3 packets before we can begin sending
data. That amounts to a delay of 300 ms. While this might not look like a lot, remember that
at any given point, a laptop being used for accessing Facebook might have thousands of
connections open to servers all over the world. The connection oriented service model
works fine for a large number of use cases, but there are a few cases where the overhead is
either significant or unnecessary. An example is video streaming. In this case, a few missing
packets do not cause a huge problem since no one notices a small number of misaligned
pixels in the video. These applications prefer a connectionless model, as described below.
[ 19 ]
Another Random Document on
Scribd Without Any Related Topics
Another classification of Propositions divides them in two classes
as follows: (1) Universal; (2) Particular.
A Universal Proposition is one in which the whole quantity of the
Subject is involved in the assertion or denial of the Predicate. For
instance: "All men are liars," by which is affirmed that all of the
entire race of men are in the category of liars, not some men but all
the men that are in existence. In the same way the Proposition: "No
men are immortal" is Universal, for it is a universal denial.
A Particular Proposition is one in which the affirmation or denial of
the Predicate involves only a part or portion of the whole of the
Subject, as for instance: "Some men are atheists," or "Some women
are not vain," in which cases the affirmation or denial does not
involve all or the whole of the Subject. Other examples are: "A few
men," etc.; "many people," etc.; "certain books," etc.; "most
people," etc.
Hyslop says: "The signs of the Universal Proposition, when
formally expressed, are all, every, each, any, and whole or words
with equivalent import." The signs of Particular Propositions are also
certain adjectives of quantity, such as some, certain, a few, many,
most or such others as denote at least a part of a class.
The subject of the Distribution of Terms in Propositions is
considered very important by Logicians, and as Hyslop says: "has
much importance in determining the legitimacy, or at least the
intelligibility, of our reasoning and the assurance that it will be
accepted by others." Some authorities favor the term, "Qualification
of the Terms of Propositions," but the established usage favors the
term "Distribution."
The definition of the Logical term, "Distribution," is: "The
distinguishing of a universal whole into its several kinds of species;
the employment of a term to its fullest extent; the application of a
term to its fullest extent, so as to include all significations or
applications." A Term of a Proposition is distributed when it is
employed in its fullest sense; that is to say, when it is employed so
as to apply to each and every object, person or thing included under
it. Thus in the proposition, "All horses are animals," the term horses
is distributed; and in the proposition, "Some horses are
thoroughbreds," the term horses is not distributed. Both of these
examples relate to the distribution of the subject of the proposition.
But the predicate of a proposition also may or may not be
distributed. For instance, in the proposition, "All horses are animals,"
the predicate, animals, is not distributed, that is, not used in its
fullest sense, for all animals are not horses—there are some animals
which are not horses and, therefore, the predicate, animals, not
being used in its fullest sense is said to be "not distributed." The
proposition really means: "All horses are some animals."
There is however another point to be remembered in the
consideration of Distribution of Terms of Propositions, which Brooks
expresses as follows: "Distribution generally shows itself in the form
of the expression, but sometimes it may be determined by the
thought. Thus if we say, 'Men are mortal,' we mean all men, and the
term men is distributed. But if we say 'Books are necessary to a
library,' we mean, not 'all books' but 'some books.' The test of
distribution is whether the term applies to 'each and every.' Thus
when we say 'men are mortal,' it is true of each and every man that
he is mortal."
The Rules of Distribution of the Terms of Proposition are as
follows:
1. All universals distribute the subject.
2. All particulars do not distribute the subject.
3. All negatives distribute the predicate.
4. All affirmatives do not distribute the predicate.
The above rules are based upon logical reasoning. The reason for
the first two rules is quite obvious, for when the subject is universal,
it follows that the whole subject is involved; when the subject is
particular it follows that only a part of the subject is involved. In the
case of the third rule, it will be seen that in every negative
proposition the whole of the predicate must be denied the subject,
as for instance, when we say: "Some animals are not horses," the
whole class of horses is cut off from the subject, and is thus
distributed. In the case of the fourth rule, we may readily see that in
the affirmative proposition the whole of the predicate is not denied
the subject, as for instance, when we say that: "Horses are animals,"
we do not mean that horses are all the animals, but that they are
merely a part or portion of the class animal—therefore, the
predicate, animals, is not distributed.
In addition to the forms of Propositions given there is another
class of Propositions known as Definitive or Substitutive Propositions,
in which the Subject and the Predicate are exactly alike in extent
and rank. For instance, in the proposition, "A triangle is a polygon of
three sides" the two terms are interchangeable; that is, may be
substituted for each other. Hence the term "substitutive." The term
"definitive" arises from the fact that the respective terms of this kind
of a proposition necessarily define each other. All logical definitions
are expressed in this last mentioned form of proposition, for in such
cases the subject and the predicate are precisely equal to each
other.
CHAPTER X.
IMMEDIATE REASONING
In the process of Judgment we must compare two concepts and
ascertain their agreement of disagreement. In the process of
Reasoning we follow a similar method and compare two judgments,
the result of such comparison being the deduction of a third
judgment.
The simplest form of reasoning is that known as Immediate
Reasoning, by which is meant the deduction of one proposition from
another which implies it. Some have defined it as: "reasoning
without a middle term." In this form of reasoning only one
proposition is required for the premise, and from that premise the
conclusion is deduced directly and without the necessity of
comparison with any other term of proposition.
The two principal methods employed in this form of Reasoning
are; (1) Opposition; (2) Conversion.
Opposition exists between propositions having the same subject
and predicate, but differing in quality or quantity, or both. The Laws
of Opposition are as follows:
I. (1) If the universal is true, the particular is true. (2) If the
particular is false, the universal is false. (3) If the universal is false,
nothing follows. (4) If the particular is true, nothing follows.
II. (1) If one of two contraries is true, the other is false. (2) If one
of two contraries is false, nothing can be inferred. (3) Contraries are
never both true, but both may be false.
III. (1) If one of two sub-contraries is false, the other is true. (2)
If one of two sub-contraries is true, nothing can be inferred
concerning the other. (3) Sub-contraries can never be both false, but
both may be true.
IV. (1) If one of two contradictories is true, the other is false. (2)
If one of two contradictories is false, the other is true. (3)
Contradictories can never be both true or both false, but always one
is true and the other is false.
In order to comprehend the above laws, the student should
familiarize himself with the following arrangement, adopted by
logicians as a convenience:
Affirmative (A)
Universal
Negative (E)
Propositions
Affirmative (I)
Particular
Negative (O)
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com